/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-12-15
*/
package com.rzico.scenic.controller.member;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Member;
import com.rzico.basics.service.MemberService;
import com.rzico.entity.Filter;
import com.rzico.entity.Pageable;
import com.rzico.entity.PageResult;
import com.rzico.scenic.entity.ScenicFavorites;
import com.rzico.scenic.model.ScenicSpotVo;
import com.rzico.scenic.service.ScenicFavoritesService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.Api;
import com.rzico.util.StringUtils;

import java.util.*;

/**
 * 我收藏的景区控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-12-15
 */
@Api(description = "我收藏的景区接口")
@RestController
@RequestMapping("/member/scenicFavorites")
public class ScenicFavoritesMemberController extends BaseController {

    @Autowired
    private ScenicFavoritesService scenicFavoritesService;

    @Autowired
    private MemberService memberService;

    /**
     * 分页查询我收藏的景区
     *
     * @return
    */
    @ApiOperation("分页查询我收藏的景区")
    @GetMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(name = "startDate", value = "开始时间", dataType = "String", paramType = "query") ,
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "String", paramType = "query")
    })
    public CommResult<ScenicFavorites> list(Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();

        Member member = memberService.getCurrent();
        if (null == member) {
            return CommResult.error("无用户信息,请先登录");
        }

        if (member!=null) {
            params.put("memberId", member.getId());
        }

        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<ScenicSpotVo> list = scenicFavoritesService.selectFavoriteScenicList(params);
        PageResult<ScenicSpotVo> pageResult = new PageResult<ScenicSpotVo>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }

    /**
     * 保存我收藏的景区
     *
     * @param scenicFavorites
     * @return
     */
    @ApiOperation("保存我收藏的景区")
    @PostMapping("/save")
    public CommResult<ScenicFavorites> save(@RequestBody ScenicFavorites scenicFavorites) {
        Member member = memberService.getCurrent();
        if (null == member) {
            return CommResult.error("无用户信息,请先登录");
        }
//        scenicFavorites.setCreateDate(new Date());
//        scenicFavorites.setModifyDate(new Date());
        scenicFavorites.setMemberId(member.getId());
        ScenicFavorites result = scenicFavoritesService.addLove(scenicFavorites);
        return CommResult.success(result);

    }


    /**
     * 批量删除我收藏的景区
     *
     * @param ids
     * @return
     */
    @Log(desc = "批量删除我收藏的景区", type = Log.LOG_TYPE.DEL)
    @ApiOperation("批量删除我收藏的景区,ids用逗号拼接")
    @PostMapping("/del/{ids}")
    public CommResult<ScenicFavorites> del(@PathVariable List<Long> ids) {

        Member member = memberService.getCurrent();
        if (null == member) {
            return CommResult.error("无用户信息,请先登录");
        }
        scenicFavoritesService.deleteMyFavoriteByIds(ids,member);
        return CommResult.success();
    }


}
